//
//  BIAdvertisementModel.m
//  BIProjectModule
//
//  Created by yown on 2022/2/14.
//

#import "BIAdvertisementModel.h"

#import <BIToolModule/NSDate+Helper.h>
#import <BIToolModule/NSString+Helper.h>

@implementation BIAdvertisementDetailModel

- (BOOL)isValide {
    if ([NSString isEmpty:self.image]) {
        return NO;
    }
    // 获取当前时间的字符串
    NSString *currentDateString = [[NSDate date] stringFromDateFormat:@"yyyy/MM/dd hh:mm:ss"];
    if ([NSString isEmpty:self.startTime] && [NSString isEmpty:self.endTime]) {
        return YES;
    } else if ([NSString isEmpty:self.startTime] && [currentDateString compare:self.endTime] == NSOrderedAscending) {
        return YES;
    } else if ([NSString isEmpty:self.endTime] && [currentDateString compare:self.startTime] == NSOrderedDescending) {
        return YES;
    } else {
        return [currentDateString compare:self.startTime] == NSOrderedDescending && [currentDateString compare:self.endTime] == NSOrderedAscending;
    }
}

@end

@implementation BIAdvertisementModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
        @"advertisementArrayModel" : @"shan_image",
    };
}

+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass {
    return @{@"advertisementArrayModel" : [BIAdvertisementDetailModel class]};
}

- (NSString *)showTime {
    return [NSString isEmpty:_showTime] ? @"3" : _showTime;
}

- (BIAdvertisementDetailModel *)showAdvertisementModel {
    __block BIAdvertisementDetailModel *tempModel = nil;
    [self.advertisementArrayModel enumerateObjectsUsingBlock:^(BIAdvertisementDetailModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isValide]) {
            tempModel = obj;
            *stop = YES;
        }
    }];
    return tempModel;
}

@end
